<?php
/*
 * Copyright (c) Taras Kudla, 2010
 */
/*
 * Gepard Console tools
 */
define("_MAX_INPUT_BUFFER",128);

class console extends kernel {
	
	public function read($message=null){
		if($message!=null) print $message;
		$stdin = fopen('php://stdin', 'r');
		$buffer=fread($stdin,_MAX_INPUT_BUFFER);
		fclose($stdin);
		return trim($buffer);
	}
	
	public function write($message){
		print $message;
	}
	
	public function writeln($message){
		print $message."\n";
	}
	
	public function confirm($message=null){
		if($message!=null) print $message." [Y]: ";
		$stdin = fopen('php://stdin', 'r');
		$buffer=fread($stdin,_MAX_INPUT_BUFFER);
		fclose($stdin);
		$c=trim($buffer);
		if( strtolower($c)!="y" || strtolower($c)!="yes")
		return false;
		else return true;
	}	
}
?>